package br.com.map.dao;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import br.com.map.model.BixoVirtual;

public class BixoVirtualDao {

    private static String PATH_SALVAR = "E:\\FIPSI\\EclipseWorkspace\\DemonhuVirtual\\BixoVirtual.txt";

    static {

    }

    public synchronized void salvarBixo() {
        try {
            BixoVirtual bicho = BixoVirtual.getInstance(); 
            FileOutputStream arquivoBixo = new FileOutputStream("PATH");
            ObjectOutputStream objGravar = new ObjectOutputStream(arquivoBixo);
            objGravar.writeObject(bicho);
            objGravar.flush();
            objGravar.close();
            arquivoBixo.flush();
            arquivoBixo.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public synchronized void carregarBixo() {
        try {
            FileInputStream arquivoLeitura = new FileInputStream("PATH");
            ObjectInputStream objLeitura = new ObjectInputStream(arquivoLeitura);
            BixoVirtual.setInstancia((BixoVirtual) objLeitura.readObject());
            objLeitura.close();
            arquivoLeitura.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
